﻿Chenxin.UI.IncomeSummary = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/IncomeSummary.ashx',
    createSearch: function() {
        return new Chenxin.UI.IncomeSummarySearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.GroupReportGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 50,
            height: 400,
            cellBorder: true,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            scope: this,
            id: 'DepartId',
            title: '实收汇总表',
            autoLoad: false,
            rowGroupSetting: [
				{ field: 'business', head: '商圈', width: 120, autoCount: false },
				{ field: 'departname', head: '门店', width: 120, autoCount: false }
			],
            columns: {
                prev: {
                    head: '前期',
                    items: {
                        old_realget: {
                            width: 100,
                            head: '实收',
                            sortable: true,
                            renderer: function(val, c, row) {
                                if (row.DepartId) {
                                    return '<a class="oldstat" style="cursor:pointer;" departid="' + row.DepartId + '">' + val + '</a>';
                                }
                                else {
                                    return val;
                                }
                            }
                        },
                        old_cname: {
                            width: 100,
                            head: '归属公司',
                            sortable: true,
                            inTotalRow: false
                        }
                    }
                },
                now: {
                    head: '本期',
                    items: {
                        now_realget: {
                            width: 100,
                            head: '实收',
                            sortable: true,
                            renderer: function(val, c, row) {
                                if (row.DepartId) {
                                    return '<a class="newstat" style="cursor:pointer;" departid="' + row.DepartId + '">' + val + '</a>';
                                }
                                else {
                                    return val;
                                }
                            }
                        },
                        now_cname: {
                            width: 100,
                            head: '归属公司',
                            sortable: true,
                            inTotalRow: false
                        }
                    }
                },
                total: {
                    width: 120,
                    head: '实收合计',
                    renderer: function(val, c, row) {
                        return (parseFloat(row.now_realget) + parseFloat(row.old_realget)).toFixed(2);
                    }
                }
            }
        });
    },
    showDetails: function(op, depid, type) {
        if (!this.detailsWin) {
            this.detailsWin = new Chenxin.UI.DetailsWin({
                id: 'x_details_win',
                actionUrl: this.actionUrl
            });
        }
        this.detailsWin.show();

        this.detailsWin.setTitle('汇总');
        this.detailsWin.grid.baseParam.op = op;
        this.detailsWin.grid.param.depid = depid;
        this.detailsWin.grid.param.typedate = type;
        Chenxin.apply(this.detailsWin.grid.param, this.search.getParamJson());
        this.detailsWin.grid.reload();
    },
    initComponent: function() {
        Chenxin.UI.IncomeSummary.superclass.initComponent.call(this);
        //this.reloadGrid();
    }
});

Chenxin.UI.DetailsWin = Chenxin.extend(Chenxin.UI.Win, {
    id: '',
    actionUrl: '',
    width: 680,
    hasFoot: true,
    height: 360,
    content: '<div id="x_details_grid"></div>',
    createBtn: function() {
        return [{
            text: '关闭',
            handler: this.hide
        }]
    },
    createGrid: function() {
        if (this.grid) {
            return;
        }
        this.grid = new Chenxin.UI.ReportGrid({
            baseParam: { op: '' },
            autoLoad: false,
            actionUrl: this.actionUrl,
            id: 'x_details_grid',
            renderTo: 'x_details_grid',
            hasCheckBox: false,
            cellBorder: true,
            modelId: 'a',
            scope: this,
            height: 311,
            hasTitle: false,
            columns: {
                contractcode: { head: '合同编号', width: 150, sortable: true, captionCol: true },
                contractdate: { head: '成交日期', width: 80, sortable: true, inTotal: false },
                paymoney: { head: '实收额', width: 200, sortable: true },
                type: { head: '类型', width: 150, sortable: true, inTotal: false }
            }
        });
    },
    initComponent: function() {
        Chenxin.UI.DetailsWin.superclass.initComponent.call(this);
        this.createGrid();
    }
});

/*
* 查询面板
*/
Chenxin.UI.IncomeSummarySearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
        this.combl = new Chenxin.UI.StructComboList({
            tbxWidth: 100
        });

        return this.combl.comboList;
    },
    afterGetParamJson: function(json) {
        if (!json.ActualDate) {
            this.autoReload = false;
            return;
        }
        this.autoReload = true;
    },
    initEvent: function() {
        $('.x_type').bind('click', { scope: this }, function(e) {
            var fn = this.value == '10' ? 'setEnable' : 'setDisable';
            e.data.scope.combl.businessDistrict[fn]();
            e.data.scope.combl.departs[fn]();

            e.data.scope.combl.businessDistrict.reset();
            e.data.scope.combl.departs.reset();
        });

        $("#txtActualDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        }).defText({
            deftxt: '结束时间'
        });

        var curdate = new Date();
        $('#txtActualDate').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));

        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });

        $('.newstat').live('click', function() {
            objSrh.scope.showDetails('getdetails', $(this).attr('departid'),1);
        });
        $('.oldstat').live('click', function() {
            objSrh.scope.showDetails('getdetails', $(this).attr('departid'),0);
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var objPg = new Chenxin.UI.IncomeSummary();
});